
<!-- 
All rights Reserved, Designed By www.youyacao.com 
@Description:代理设置
@author:成都市一颗优雅草科技有限公司     
@version 松鼠聚合直播系统v2.0
注意：本前端源码遵循 MulanPSL-2.0开源协议（木兰宽松许可证）本内容仅限于个人参考，禁止用于其他的商业用途
需要商业用途或者定制开发等可访问songshu.youyacao.com   联系QQ:422108995 23625059584

 -->

<template>
    <div>
        <van-popup
                v-model="showDialog"
                closeable
                style="width: 80%;"
        >
            <div style="text-align: center;padding: 20px;font-weight: bold; font-size: 16px;">修改代理密码</div>
            <div style="text-align: center;padding: 10px;">请输入6位以上的密码</div>
            <div style="text-align: center;padding: 10px;"><input type="password" name="password" v-model="password" placeholder="请输入新密码" style="width: 80%;" /></div>
            <div style="text-align: center;padding: 10px;"><van-button @click="domodifypass()">确认修改</van-button></div>
        </van-popup>
        <van-popup
                v-model="showYqmDialog"
                closeable
                style="width: 80%;"
        >
            <div style="text-align: center;padding: 20px;font-weight: bold; font-size: 16px;">修改代理邀请码</div>
            <div style="text-align: center;padding: 10px;">邀请码不允许重复</div>
            <div style="text-align: center;padding: 10px;"><input type="text" name="password" v-model="yqm_text" placeholder="请输入邀请码" style="width: 80%;" /></div>
            <div style="text-align: center;padding: 10px;"><van-button @click="doModifyYqm()">确认修改</van-button></div>
        </van-popup>
        <van-popup
                v-model="showMoneyDialog"
                closeable
                style="width: 80%;"
        >
            <div style="text-align: center;padding: 20px;font-weight: bold; font-size: 16px;">向他人转点</div>
            <div style="text-align: center;padding: 10px;">
                <span v-if="userinfo.user_type=='daili'">请输入转点数量，并确保点数充足</span>
                <span v-if="userinfo.user_type=='admin'">正数为加点，负数为减点</span>
            </div>
            <div style="text-align: center;padding: 10px;"><input type="text" name="money" v-model="paymoney" placeholder="请输入转点数量" style="width: 80%;" /></div>
            <div style="text-align: center;padding: 10px;"><van-button @click="dopaymoney()">确认转点</van-button></div>
        </van-popup>
        <van-search
                v-model="keyword"
                placeholder="请输入代理会员名"
                show-action
                shape="round"
                @search="onSearch"
        >
            <div slot="action" @click="onSearch">搜索</div>
        </van-search>
        <van-tabs v-model="active" @change="changeTab()">
            <van-tab title="全部代理">
                <div class="list-item" v-for="(item,index) in list.data">
                    <div class="title"><b>代理名会员名：</b>{{item.username}}</div>
                    <div class="content">
                        <van-row>
                            <van-col span="12">
                                <div class="num">{{item.money}}</div>
                                <div class="option-title">剩余点数</div>
                            </van-col>
                            <van-col span="12">
                                <div class="num">{{item.tuijian_count}}</div>
                                <div class="option-title">会员人数</div>
                            </van-col>
                        </van-row>
                    </div>
                    <div class="time">邀请码：{{item.tuijianma}}</div>
                    <div class="time">注册时间：{{item.reg_time}}</div>
                    <div class="time">最后登陆：{{item.last_login_time}}</div>
                    <div class="time end-time" v-if="item.delete_time">封停时间：{{item.delete_time}}</div>
                    <div class="controll-box">
                        <van-button type="default" size="small" @click="modifypass(item.id)">重置密码</van-button>
                        <van-button style="margin-left: 20px;" type="info" size="small" @click="pay_money(item.id)">向他转点</van-button>
                        <van-button style="margin-left: 20px;" type="warning" size="small" @click="alter_yqm(item.id,item.tuijianma)">修改邀请码</van-button>
                        <van-button style="margin-left: 20px;" type="danger" size="small" @click="disable_user(item.id)" v-if="item.delete_time==''">封号</van-button>
                        <van-button style="margin-left: 20px;" type="primary" size="small" @click="able_user(item.id)" v-if="item.delete_time">解封</van-button>
                    </div>
                </div>
                <van-pagination
                        v-model="list.current_page"
                        :total-items="list.total"
                        :items-per-page="list.per_page"
                        @change="changePage"
                        v-if="list.last_page>1"
                />
            </van-tab>
            <van-tab title="已封号代理">
                <div class="list-item" v-for="(item,index) in list.data">
                    <div class="title"><b>代理名会员名：</b>{{item.username}}</div>
                    <div class="content">
                        <van-row>
                            <van-col span="12">
                                <div class="num">{{item.money}}</div>
                                <div class="option-title">剩余点数</div>
                            </van-col>
                            <van-col span="12">
                                <div class="num">{{item.tuijian_count}}</div>
                                <div class="option-title">会员人数</div>
                            </van-col>
                        </van-row>
                    </div>
                    <div class="time">邀请码：{{item.tuijianma}}</div>
                    <div class="time">注册时间：{{item.reg_time}}</div>
                    <div class="time">最后登陆：{{item.last_login_time}}</div>
                    <div class="time end-time" v-if="item.delete_time">封停时间：{{item.delete_time}}</div>
                    <div class="controll-box">
                        <van-button type="default" size="small" @click="modifypass(item.id)">重置密码</van-button>
                        <van-button style="margin-left: 20px;" type="info" size="small" @click="pay_money(item.id)">向他转点</van-button>
                        <van-button style="margin-left: 20px;" type="warning" size="small" @click="alter_yqm(item.id,item.tuijianma)">修改邀请码</van-button>
                        <van-button style="margin-left: 20px;" type="danger" size="small" @click="disable_user(item.id)" v-if="item.delete_time==''">封号</van-button>
                        <van-button style="margin-left: 20px;" type="primary" size="small" @click="able_user(item.id)" v-if="item.delete_time">解封</van-button>
                    </div>
                </div>
                <van-pagination
                        v-model="list.current_page"
                        :total-items="list.total"
                        :items-per-page="list.per_page"
                        @change="changePage"
                        v-if="list.last_page>1"
                />
            </van-tab>
        </van-tabs>
    </div>
</template>

<script>
    import global_ from '../Global';
    import { Toast } from 'vant';
    import { Notify } from 'vant';
    import { Dialog } from 'vant';
    export default {
        name: "member",
        props:["userinfo"],
        data(){
            return {
                keyword:"",
                active:0,
                list:{},
                password:'',
                showDialog:false,
                uid:0,
                showMoneyDialog:false,
                paymoney:"",
                showYqmDialog:false,
                yqm_text:""

            }
        },
        created(){
           this.loadInfo(0,1);
        },
        methods:{
            loadInfo:function (type,page,keyword) {
                var toast = Toast.loading({
                    mask: true,
                    duration: 0,
                    message: '加载中...'
                });
                this.$axios.get(global_.serverUrl+"admin/member/daililist",{
                    params:{
                        type:type,
                        page:page,
                        keyword:keyword ? keyword : ''
                    }
                }).then((res)=>{
                    toast.clear();
                    if(res.code == 1){
                        this.list = res.data;
                    }
                }).catch(()=>{
                    toast.clear();
                });
            },
            changeTab:function(){
                this.keyword = "";
                this.loadInfo(this.active,1);
            },
            modifypass:function (uid) {
                this.showDialog = true;
                this.password = "";
                this.uid = uid;
            },
            domodifypass:function(){
                var toast = Toast.loading({
                    mask: true,
                    duration: 0,
                    message: '提交中...'
                });
                this.$axios.post(global_.serverUrl+"admin/member/modifypass",{
                    password:this.password,
                    uid:this.uid
                }).then((res)=>{
                    toast.clear();
                    if(res.code != 1){
                        Toast(res.msg);
                    }else{
                        this.showDialog = false;
                        Notify({ type: 'success', message: '密码修改成功' });
                    }
                }).catch(()=>{
                    toast.clear();
                });
            },
            alter_yqm:function(id,yqm){
                this.showYqmDialog = true;
                this.uid = id;
                this.yqm_text = yqm;

            },
            doModifyYqm:function(){
                var that = this;
                var toast = Toast.loading({
                    mask: true,
                    duration: 0,
                    message: '提交中...'
                });
                this.$axios.post(global_.serverUrl+"admin/member/modifyyqm",{
                    tuijianma:this.yqm_text,
                    uid:this.uid
                }).then((res)=>{
                    toast.clear();
                    if(res.code != 1){
                        Toast(res.msg);
                    }else{
                        Notify({ type: 'success', message: '邀请码修改成功' });
                        that.loadInfo(that.active,that.list.current_page,that.keyword);
                    }
                }).catch(()=>{
                    toast.clear();
                });
            },
            changePage:function (page) {
                this.loadInfo(this.active,page);
            },
            onSearch:function () {
                this.loadInfo(this.active,1,this.keyword);
            },
            pay_money:function (uid) {
                this.showMoneyDialog = true;
                this.paymoney = "";
                this.uid = uid;
            },
            dopaymoney:function () {
                var that = this;
                var toast = Toast.loading({
                    mask: true,
                    duration: 0,
                    message: '提交中...'
                });
                this.$axios.post(global_.serverUrl+"admin/member/paymoney",{
                    paymoney:this.paymoney,
                    uid:this.uid
                }).then((res)=>{
                    toast.clear();
                    if(res.code != 1){
                        Toast(res.msg);
                    }else{
                        this.showMoneyDialog = false;
                        Dialog.confirm({
                            title: '订单确认',
                            message: res.msg
                        }).then(() => {
                            toast = Toast.loading({
                                mask: true,
                                duration: 0,
                                message: '提交中...'
                            });
                            that.$axios.post(global_.serverUrl+"admin/member/dopaymoney",{
                                orderid:res.data
                            }).then((res2)=>{
                                toast.clear();
                                if(res2.code != 1){
                                    Toast(res2.msg);
                                }else{
                                    Notify({ type: 'success', message: '转点成功' });
                                    that.loadInfo(that.active,that.list.current_page,that.keyword);
                                }
                            }).catch(()=>{
                                toast.clear();
                            });
                        });
                    }
                }).catch(()=>{
                    toast.clear();
                });
            },
            disable_user:function (uid) {
                Dialog.confirm({
                    title: '提示',
                    message: '封停后将禁止代理一切操作，是否封停此账号？'
                }).then(() => {
                    this.$axios.post(global_.serverUrl+"admin/member/disable_user",{
                        uid:uid
                    }).then((res)=>{
                        if(res.code != 1){
                            Toast(res.msg);
                        }else{
                            Notify({ type: 'success', message: res.msg });
                            this.loadInfo(this.active,this.list.current_page,this.keyword);
                        }
                    });
                });
            },
            able_user:function (uid) {
                Dialog.confirm({
                    title: '提示',
                    message: '是否解封此账号？'
                }).then(() => {
                    this.$axios.post(global_.serverUrl+"admin/member/able_user",{
                        uid:uid
                    }).then((res)=>{
                        if(res.code != 1){
                            Toast(res.msg);
                        }else{
                            Notify({ type: 'success', message: res.msg });
                            this.loadInfo(this.active,this.list.current_page,this.keyword);
                        }
                    });
                });
            }
        }
    }
</script>

<style scoped>
.list-item{
    padding: 10px;
    background: #ffffff;
    margin: 10px 0px;
}
.list-item .title{
    padding: 5px 0px;
    padding-bottom: 10px;
}
.list-item .content{
    text-align: center;
    padding: 10px 0px;
    background: #f4f6f9;
    border-radius: 10px;
}
.list-item .content .num{
    font-weight: bold;
    font-size: 16px;
    padding: 10px;
}
.list-item .content .option-title{
    color: #7d7e80;
    font-size: 12px;
}
.list-item .time{
    padding: 5px;
    color: #7d7e80;
    font-size: 12px;
}
.list-item .end-time{
    color: #ff756d;
}
.controll-box{
    padding: 5px;
    text-align: center;
    border-top: #e7e7e7 1px solid;
    padding-top: 10px;
}
</style>
